// 	ID : pallab81
// 	PROG : 481
// 	LANG : C++
// 	2011-08-24-22.06.39 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )


// algorithm from
// http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence.cpp
// complexity O(nlogn) algorithm - output sensitive - O(nlogk)

inline void wait( double seconds ) {
    double endtime = clock() + ( seconds*CLOCKS_PER_SEC );
    while( clock() < endtime ) {
        ;
    }
}
vector<int> v;
vector<int> l;
int N;
inline void find_lis(vector<int> &a, vector<int> &b) {
    vector<int> p(a.size());
    int u, v;

    if (a.empty()) return;

    b.push_back(0);

    for (size_t i = 1; i < SZ(a); i++) {
        // If next element a[i] is greater than last element of current longest subsequence a[b.back()], just push it at back of "b" and continue
        if (a[b.back()] < a[i]) {
            p[i] = b.back();
            b.push_back(i);
            continue;
        }

        // Binary search to find the smallest element referenced by b which is just bigger than a[i]
        // Note : Binary search is performed on b (and not a). Size of b is always <=k and hence contributes O(log k) to complexity.
        for (u = 0, v = SZ(b)-1; u < v;) {
            int c = (u + v) / 2;
            if (a[b[c]] < a[i]) u=c+1;
            else v=c;
        }

        // Update b if new value is smaller then previously referenced value
        if (a[i] < a[b[u]]) {
            if (u > 0) p[i] = b[u-1];
            b[u] = i;
        }
    }

    for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v;
}

inline void Proc() {
    find_lis(v,l);
    N = SZ(l);
    printf("%d\n-\n",N);
    for( int i = 0 ; i < N; ++i ){
        printf("%d\n",v[ l[i] ]);
    }
}
int main() {
//#ifndef ONLINE_JUDGE
//    freopen("in.txt","rt",stdin);
//#endif

    while( scanf("%d",&N)==1 ) {
        v.pb( N );
    }
    Proc();

    return 0;
}
